package com.bluedon.ism.commons.entity;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * 权限表
 */
@Entity
@Table(name = "PERMISSION")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Permission implements java.io.Serializable {

	private long pid;
	private OperateAuth operateAuth;
	private Menu menu;
	private String permissionName;
	private String permissionCode;
	private String description;
	private Integer permType;
	private Set<RolePermission> rolePermissions = new HashSet<RolePermission>(0);


    @Id
    @GeneratedValue(strategy = IDENTITY)
	@Column(name = "PID", unique = true, nullable = false, precision = 10, scale = 0)
	public long getPid() {
		return this.pid;
	}

	public void setPid(long pid) {
		this.pid = pid;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "OPERATE_AUTH_ID")
	public OperateAuth getOperateAuth() {
		return this.operateAuth;
	}

	public void setOperateAuth(OperateAuth operateAuth) {
		this.operateAuth = operateAuth;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MENU_ID")
	public Menu getMenu() {
		return this.menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	@Column(name = "PERMISSION_NAME", length = 100)
	public String getPermissionName() {
		return this.permissionName;
	}

	public void setPermissionName(String permissionName) {
		this.permissionName = permissionName;
	}

    @Column(name = "PERMISSION_CODE", unique=true, nullable=false, length = 100)
	public String getPermissionCode() {
        return permissionCode;
    }

    public void setPermissionCode(String permissionCode) {
        this.permissionCode = permissionCode;
    }

    @Column(name = "DESCRIPTION")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "PERM_TYPE", precision = 2, scale = 0)
	public Integer getPermType() {
		return this.permType;
	}

	public void setPermType(Integer permType) {
		this.permType = permType;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "permission",cascade = CascadeType.ALL)
	public Set<RolePermission> getRolePermissions() {
		return this.rolePermissions;
	}

	public void setRolePermissions(Set<RolePermission> rolePermissions) {
		this.rolePermissions = rolePermissions;
	}

}
